<template>
  <uni-popup ref="popup">
    <view class="pop-content">
      <text class="title">{{ title }}</text>
      <view class="con center">
        <text class="text">{{ text }}</text>
      </view>
      <view class="btn-group row">
        <view class="btn center" @click="close">
          <view class="pink-mark"></view>
          <text>{{ cancelText }}</text>
        </view>
        <view class="btn center red" @click="confirm">
          <text>{{ confirmText }}</text>
        </view>
      </view>
    </view>
  </uni-popup>
</template>

<script>
/**
 * 自定义 确认对话框
 * @prop title 标题
 * @prop text 提示内容
 * @prop cancelText 取消按钮文字
 * @prop confirmText 确认按钮文字
 * @event onConfirm 确认按钮点击时触发
 */
export default {
  data() {
    return {};
  },
  props: {
    title: String,
    text: String,
    cancelText: {
      type: String,
      default: '取消',
    },
    confirmText: {
      type: String,
      default: '确认',
    },
  },
  methods: {
    confirm() {
      this.$emit('onConfirm');
      this.close();
    },
    open() {
      this.$refs.popup.open();
    },
    close() {
      this.$refs.popup.close();
    },
  },
};
</script>

<style scoped lang="scss">
.pop-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 580rpx;
  padding-top: 36rpx;
  background-color: #fff;
  border-radius: 24rpx;
  overflow: hidden;

  .title {
    font-size: 42rpx;
    color: #333;
    line-height: 58rpx;
    font-weight: 700;
  }
  .con {
    padding: 36rpx 40rpx 54rpx;
  }
  .text {
    width: 460rpx;
    font-size: 30rpx;
    color: #333;
    line-height: 40rpx;
    text-align: center;
  }
  .btn-group {
    width: 100%;
  }
  .btn {
    position: relative;
    top: 0;
    flex: 1;
    height: 88rpx;
    line-height: 88rpx;
    font-size: 36rpx;
    color: #f55348;
    margin: 0 30rpx 20rpx;
    border-radius: 45px;

    &:last-child {
      color: #ffffff;
    }
  }
  .pink-mark {
    position: absolute;
    top: 0;
    left: 0;
    border-radius: 45px;
    background: linear-gradient(151deg, #f75248 0%, #f5473b 100%);
    height: 88rpx;
    width: 100%;
    opacity: 0.1;
  }
  .red {
    background: linear-gradient(151deg, #f75248 0%, #f5473b 100%);
  }
}
</style>
